package org.dromara.akali.service.impl;

import org.dromara.akali.annotation.AkaliHot;
import org.dromara.akali.service.HelloService;
import org.dromara.akali.annotation.AkaliFallback;
import org.dromara.akali.enums.FlowGradeEnum;
import org.springframework.stereotype.Service;

@Service
public class HelloServiceImpl implements HelloService {

    @AkaliFallback(grade = FlowGradeEnum.FLOW_GRADE_THREAD, count = 10)
    @Override
    public String sayHi(String name) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "hi,"+name + " | " + System.currentTimeMillis();
    }

    @Override
    public String sayHiFallback(String name) {
        return "fallback str";
    }



    @AkaliHot(grade = FlowGradeEnum.FLOW_GRADE_THREAD, count = 10, duration = 5)
    @Override
    public String getSkuInfo(String skuCode){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("从数据库查询SkuInfo:" + skuCode);
        return skuCode + " | " + System.currentTimeMillis();
    }
}
